package com.zhisheng.springboothello.demos.web.param;

import com.zhisheng.springboothello.demos.web.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

@RestController
@RequestMapping("/wyq")
public class Param {


@PostMapping("/wyq")
    public String getUser(HttpServletRequest  request){

        String name = request.getParameter("name");
        String age = request.getParameter("age");
        System.out.println(name+","+age);
        return "name:"+name+" age:"+age;
    }
    @PostMapping("/wyq2")
    public String getUser2(@RequestParam("name") String username, Integer age){
        System.out.println(username+","+age);
        return "name:"+username+" age:"+age;
    }
    @PostMapping
    public String getUser3(@RequestParam("name") String username, Integer age){
        System.out.println(username+","+age);
        return "name:"+username+" age:"+age;
    }
   /* @PostMapping
    public String getUser4(@RequestParam("name") String username, Integer age){
        System.out.println(username+","+age);
        return "name:"+username+" age:"+age;
    }*/
   @PostMapping("wyqq")
   public String getUser4(User user){
       System.out.println(user);
       return user.toString();
   }
    @PostMapping("wyqq1")
    public String getUser5(String[] hoppy){
        System.out.println(Arrays.toString(hoppy));
        return Arrays.toString(hoppy);
    }

    @PostMapping("wyqq2")
    public String getUser6(@RequestParam ArrayList<String> hoppy){
        System.out.println(hoppy);
        return hoppy.toString();
    }
    @PostMapping("wyqq3")
    public String getUser7( @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime time){
        System.out.println(time);
        return time.toString();
    }
    @PostMapping("wyqq4")
    public String getUser8(@RequestBody User user){
        System.out.println(user);
        return user.toString();
    }
    @PostMapping("wyqq5/{name}/{age}")
    public String getUser9(@PathVariable("name") String name ,@PathVariable("age") Integer age){
        System.out.println(name+","+age);
        return name+","+age;
    }

}
